package com.hyt.it.ogt.ks.controller;


import java.util.List;

import javax.annotation.Resource;

import com.hyt.it.ogt.ks.feign.model.MessageDTO;
import org.springframework.web.bind.annotation.*;

import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.common.apiInfor.DataType;
import com.hyt.common.apiInfor.ParamType;
import com.hyt.it.ogt.ks.enums.BizStatusCode;
import com.hyt.it.ogt.ks.feign.KwClient;
import com.hyt.it.ogt.ks.feign.model.TestingMessageDTO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import io.swagger.annotations.ApiSort;
import lombok.extern.slf4j.Slf4j;

@Api(tags = "13.消息对话接口", value = "消息对话接口")
@ApiSort(13)
@Slf4j
@RestController
@RequestMapping("/ks/message/")
public class MessageController {
    @Resource
    private KwClient kwClient;

    @GetMapping("getCandidateMessageList")
    @ApiOperation(value = "13.1 获取消息对话列表", response = TestingMessageDTO.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试ID", dataType = DataType.STRING,
                    paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "candidateId", value = "考生ID", dataType = DataType.STRING,
                    paramType = ParamType.QUERY, required = true)
    })
    @ApiOperationSort(1)
    public ApiResponse<List<TestingMessageDTO>> getCandidateMessageList(@RequestParam String examId, @RequestParam String candidateId) {
        try {
            ApiResponse<List<TestingMessageDTO>> res = kwClient.getCandidateMessageList(examId, candidateId);
            return ApiResponse.<List<TestingMessageDTO>>builder().code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(res.getData()).build();
        } catch (Exception e) {
            log.error("getCandidateMessageList获取消息对话列表失败: ", e);
            return ApiResponse.<List<TestingMessageDTO>>builder().code(BizStatusCode.GET_CANDIDATE_MESSAGE_FAIL.getCode()).build();
        }
    }

    @PostMapping("updateNoticeState")
    @ApiOperation(value = "13.2 考生确认信息")
    @ApiOperationSort(2)
    public ApiResponse updateNoticeState(@RequestBody MessageDTO messageDTO) {
        try {
            ApiResponse res = kwClient.updateNoticeState(messageDTO);
            return ApiResponse.builder().code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .build();
        } catch (Exception e) {
            log.error("修改状态失败: ", e);
            return ApiResponse.builder().code(BizStatusCode.UPDATE_CANDIDATE_MESSAGE_STATE_FAIL.getCode()).build();
        }
    }
}
